package user

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"weekly-exam/internal/model/service"
)

type Lists struct {
	UserName string `form:"userName" json:"userName" xml:"userName" binding:"required"`
	Page     int    `form:"page" json:"page" xml:"page" binding:"required"`
	PageSize int    `form:"pageSize" json:"pageSize" xml:"pageSize" binding:"required"`
}

func List(c *gin.Context) {
	var json Lists
	if err := c.ShouldBindJSON(&json); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	userName := json.UserName
	page := json.Page
	pageSize := json.PageSize
	list, err := service.UserList(userName, page, pageSize)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    500,
			"message": "没有该用户",
		})
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "查询成功",
		"data":    list,
	})
}
